<?php
mysql_select_db($database_Infinitus, $Infinitus);
$query_rsUsuarios = "SELECT user_login, user_pass, user_email, user_status FROM wp_users";
$rsUsuarios = mysql_query($query_rsUsuarios, $Infinitus) or die(mysql_error());
$row_rsUsuarios = mysql_fetch_assoc($rsUsuarios);
$totalRows_rsUsuarios = mysql_num_rows($rsUsuarios);
 
mysql_free_result($rsUsuarios);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['user_id'])) {
	require_once('config.php');
	//require_once( ABSPATH . '\functions\pluggable.php' );
	//require_once( ABSPATH . '\functions\class-phpass.php' );

  $loginUsername=$_POST['user_id'];
  //$password= wp_hash_password($_POST['user_pw']);
  $password= $_POST['user_pw'];
  
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "index.php";
  $MM_redirectLoginFailed = "acceso_error_vista.php";
  $MM_redirecttoReferrer = false;
  $MM_redirectMessage="";

	mysql_select_db($database_Infinitus, $Infinitus);
  
  $LoginRS__query=sprintf("SELECT user_login, user_pass FROM wp_users WHERE user_login=%s AND user_pass=%s AND user_activation_key='admin' ",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $Infinitus) or die(mysql_error());
  $row_rsLogin = mysql_fetch_assoc($LoginRS);
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser){
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess.$MM_redirectMessage );
  }
  else {
	 $MM_redirectMessage="?msgerror=";
	 if(trim($loginUsername)<>trim($row_rsLogin["user_login"])){
		$MM_redirectMessage .="Usuario no existe <br>";
	 }
	 if(trim($password)<>trim($row_rsLogin["user_pass"])){
		$MM_redirectMessage .="Clave incorrecta <br>";
	 }
		header("Location: ". $MM_redirectLoginFailed.$MM_redirectMessage );
  }
}
?>
<form action="<?php echo $loginFormAction; ?>" method="POST" enctype="application/x-www-form-urlencoded" name="acceso" target="_self">
  <table width="200" border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
<td>Usuario</td>
<td>&nbsp;</td>
      <td><input type="text" name="user_id" id="user_id"></td>
    </tr>
    <tr>
<td>Clave</td>
<td>&nbsp;</td>
      <td><input type="password" name="user_pw" id="user_pw"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
<td>&nbsp;</td>
      <td><input type="submit" name="accesar_btn" id="accesar_btn" value="Ingresar"></td>
    </tr>
  </table>

</form>